import { NgModule } from '@angular/core';
// 导入 RouterModule 和 Routes，以便该应用具有路由功能
import { RouterModule, Routes } from '@angular/router';
// 导入 HeroesComponent，它将告诉路由器要去什么地方。
import { HeroesComponent } from './heroes/heroes.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { HeroDetailComponent } from './hero-detail/hero-detail.component';

// path: 用来匹配浏览器地址栏中 URL 的字符串。
// component: 导航到该路由时，路由器应该创建的组件
const routes: Routes = [
  { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
  { path: 'heroes', component: HeroesComponent },
  { path: 'dashboard', component: DashboardComponent },
  { path: 'detail/:id', component: HeroDetailComponent },
];

// 会初始化路由器，并开始监听浏览器地址的变化
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
